<?php

require_once("Model/LoginHandler.php");

class LoginView 
{
	//Privata strängar
	private $nameLocation = "userName"; //CoockiePlats
	private $passLocation = "password"; //CoockiePlats
	
	private $remName;
 	
	private $getUserName = "userName";
	private $getPassword = "password";
	private $getLoginKey = "login";
	private $getCheckbox = "checkbox";
	private $getLogoutKey = "logout";
 	
	//Sparar 2 coockies om anv klickat i "Remember me"
	public function DidUserRemember() 
	{	    		
		if (isset($_GET[$this->getCheckbox]) == TRUE)
		{
			setcookie($this->nameLocation, $this->GetUserName(), time() + 60);
			setcookie($this->passLocation, $this->GetPassword(), time() + 60);
		}	
		else if($this->TriedToLogOut())
		{
			setcookie($this->nameLocation, "", time() - 60);
			setcookie($this->passLocation, "", time() - 60);		
		}	
	}
	
	//Retunerar TRUE om det finns användar coockies satta
	public function AutoLogin()
	{
		if (isset($_COOKIE[$this->nameLocation]) == TRUE
			&& isset($_COOKIE[$this->passLocation]) == TRUE)
		{
			return TRUE;
		}		
		
	}
	
	//Retunerar ett HTML formulär för inloggning
	public function DoLoginBox() 
	{
	    return $loginForm = 

	    "<form name='frmLoginUser' id='frmLoginUser' method='get'>	    		
			<p>Name:</p>			
			<input type='text' value='$this->remName' name='$this->getUserName' id='userName' size='50' /><br/>
			<p>Password:</p>							
			<input type='password' name='$this->getPassword' id='password' size='50' /><br/><br/>  			
			<input type='submit' value='Login' name='$this->getLoginKey' id='login' />	
			<input type='checkbox' value='check' name='$this->getCheckbox' id='check' /> Remember me			  			
		</form>";
	}
	
	//Retunerar ett HTML formulär för en utloggningsknapp		
	public function DoLogoutBox() 
	{
	    return $logoutButton =
	    
		"<form name='frmLoginUser' id='frmLoginUser' method='get'>
			<input type='submit' value='Logout' name='$this->getLogoutKey' id='logout' />	    	
		</form>";
				
	}
		
	//Retunerar användarnamnet om ett sådant finns, annars NULL  
	public function GetUserName() 
	{
	  	
		if (isset($_GET[$this->getUserName]) == TRUE)
		{				 		
			return $_GET[$this->getUserName];
		}
		
		return NULL;		
	}
	
	//Retunerar lösenordet om ett sådant finns, annars null  
	public function GetPassword() 
	{	    		
		if (isset($_GET[$this->getPassword]) == TRUE)
		{
			return $_GET[$this->getPassword];
		}
				
		return NULL;			
	}
	
	//Retunerar TRUE om anv klickar på loginknappen  
	public function TriedToLogin() 
	{
			
		if (isset($_GET[$this->getLoginKey]))
		{   			
			return TRUE;  	
		}
				
		return FALSE;
	   		
	}
	
	//Retunerar TRUE om anv klickar på logoutknappen  
	public function TriedToLogOut() 
	{
	   			
		if (isset($_GET[$this->getLogoutKey]))
		{   				
			return TRUE;
		}
				
		return FALSE;
	   		
	}
	   					       	
} 
  

?>
  